import { Route, Routes, HashRouter } from 'react-router-dom';
import * as React from 'react';

import AuthProvider from '../components/auth/auth-provider';
import { RequireAuth } from '../components/auth/require-auth';
import { MainLayout } from '../layout';
import { LoginPage, WxLoginPage, SettingsPage, WxxQRCodeLoginPage, WxxLoginHomePage, ChatPage } from '../pages';

import { MGApplicationProps } from '../api';


export const MGApplication: React.FC<MGApplicationProps> = (props: MGApplicationProps) => {

    //
    return (
        <HashRouter>
            <AuthProvider>
                <Routes>
                    <Route element={<RequireAuth><MainLayout  {...props} /></RequireAuth>}>
                        {/* 需要登录 */}
                        {
                            props.pages && props.pages.map((item, index) => <Route key={index} {...item} />)
                        }
                        <Route path='/_chat' element={<ChatPage />} />
                        <Route path='/_settings' element={<SettingsPage />} />
                    </Route>
                    {/* 登录 */}
                    <Route path='/_login' element={<WxxLoginHomePage />} />
                    <Route path='/login' element={<LoginPage />} />
                    <Route path='/tklogin' element={<WxLoginPage />} />
                    <Route path='/wxxlogin' element={<WxxQRCodeLoginPage />} />
                </Routes>
            </AuthProvider>
        </HashRouter>
    )
};

export default MGApplication; 
